﻿using LanguagePolish.Base;
using LanguagePolish.EntityModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace LanguagePolish.Controls
{
    /// <summary>
    /// Логика взаимодействия для CalendarCell.xaml
    /// </summary>
    public partial class CalendarCell : UserControl
    {
        public event EventHandler<AddLessonEventArgs> AddLesson;
        public event EventHandler<EditLessonEventArgs> EditLesson;
        public event EventHandler<RemoveLessonEventArgs> RemoveLesson;

        public static readonly DependencyProperty DateProperty =
              DependencyProperty.Register("Date", typeof(DateTime),
              typeof(CalendarCell), new FrameworkPropertyMetadata(DateTime.Now));

        public DateTime Date
        {
            get { return (DateTime)GetValue(DateProperty); }
            set { SetValue(DateProperty, value); }
        }

        public static readonly DependencyProperty IsActiveDateProperty =
          DependencyProperty.Register("IsActiveDate", typeof(bool), typeof(CalendarCell));

        public bool IsActiveDate
        {
            get { return (bool)GetValue(IsActiveDateProperty); }
            set { SetValue(IsActiveDateProperty, value); }
        }

        public static readonly DependencyProperty EnableMenuProperty =
            DependencyProperty.Register("EnableMenu", typeof(bool), typeof(CalendarCell));

        public bool EnableMenu
        {
            get { return (bool)GetValue(EnableMenuProperty); }
            set { SetValue(EnableMenuProperty, value); }
        }

        public List<Lesson> CellItems
        {
            set
            {
                elems.ItemsSource = value;
            }
            get
            {
                return (List<Lesson>)elems.ItemsSource;
            }
        }

        public CalendarCell()
        {
            InitializeComponent();
        }

        private void AddLessonClick(object sender, RoutedEventArgs e)
        {
            if (AddLesson != null)
                AddLesson(this, new AddLessonEventArgs(Date));
        }

        private void EditLessonClick(object sender, RoutedEventArgs e)
        {
            if (EditLesson != null)
            {
                FrameworkElement s = (FrameworkElement)sender;
                Lesson les = (Lesson)s.Tag;
                EditLesson(this, new EditLessonEventArgs(les));
            }
        }

        private void RemoveLessonClick(object sender, RoutedEventArgs e)
        {
            if (RemoveLesson != null)
            {
                FrameworkElement s = (FrameworkElement)sender;
                Lesson les = (Lesson)s.Tag;
                RemoveLesson(this, new RemoveLessonEventArgs(les));
            }
        }
    }
}
